package dk.dtu.android.transport;

import dk.dtu.android.gui.Debugging;
import dk.dtu.android.gui.DepActivity;
import dk.dtu.android.gui.OrderActivity;
import dk.dtu.android.gui.TInfoActivity;
import dk.dtu.android.transport.R;
import dk.dtu.android.transport.db.BaseDbAdapter;
import dk.dtu.android.transport.gps.GPSAlarmReceiver;
import dk.dtu.android.transport.gps.GPSService;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
        Log.d("Transport", "Transport has started!");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		BaseDbAdapter.initialize(this);
		GPSAlarmReceiver.initialize(this);
		
        FacebookLogin.loginIfRequired(this);
        GPSAlarmReceiver.startAlarm();
        GPSService.serviceStarter(getBaseContext());

		TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

		TabSpec departTab = tabHost.newTabSpec("tid1");
		TabSpec tInfoTab = tabHost.newTabSpec("tid1");
		TabSpec orderTab = tabHost.newTabSpec("tid1");

		departTab.setIndicator("Departures").setContent(new Intent(this,DepActivity.class));
		tInfoTab.setIndicator("Trip Information").setContent(new Intent(this,TInfoActivity.class));
		orderTab.setIndicator("Order Klip").setContent(new Intent(this,OrderActivity.class));

		tabHost.addTab(tInfoTab);
		tabHost.addTab(departTab);
		tabHost.addTab(orderTab);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.debug, menu);
	    return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	    case R.id.itmDebug:
	        Debugging.startThisActivity(MainActivity.this);
	        return true;
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}

}
